using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NBlock.MVCExtensions;
using Cost.Models;

namespace Cost.Controllers
{
    public class ProjectSiteController : Controller
    {
        #region 构造函数
        private readonly ICostRepository<ProjectSite> projectsiteRepository;

        public ProjectSiteController(ICostRepository<ProjectSite> projectsiteRepository)
        {
            this.projectsiteRepository = projectsiteRepository;
        }
        #endregion

        //
        // GET: /ProjectSite/

        public ViewResult Index()
        {
            return View();
        }

        //
        // GET: /ProjectSite/Edit/5

        public ActionResult Edit(string id)
        {
            var data = projectsiteRepository.Find(id) ?? new ProjectSite();
            return View(data);
        }

        //
        // POST: /ProjectSite/Save

        [HttpPost]
        public JsonResult Save(string id)
        {
            var data = projectsiteRepository.Find(id) ?? new ProjectSite();
            TryUpdateModel(data);
            projectsiteRepository.Save(data);
            return Json(nbAjaxMessage.Successful);
        }

        //
        // POST: /ProjectSite/Delete/5

        [HttpPost]
        public JsonResult Delete(string id)
        {
            projectsiteRepository.Delete(id);
            return Json(nbAjaxMessage.Successful);
        }

        [HttpPost]
        public JsonResult DeleteAll(string Ids)
        {
            var items = Ids.Split(',');
            projectsiteRepository.DeleteAll(d => items.Contains(d.Id));
            return Json(nbAjaxMessage.Successful);
        }

        //
        // POST: /ProjectSite/List

        [HttpPost]
        public JsonResult List(nbPageInfo pager, nbSearchCondition where)
        {
            var pageData = projectsiteRepository.GetPageable(pager, where);
            var data = pager.ToGridData(pageData);
            return Json(data);
        }
    }
}

